<?php 
class system_admin 
{ 
	function admin_system_list() 
	{ 
		global $mysql_conn,$v_file;
		$list_page = $_GET['list_page'];
		$list_num = $_GET['list_num'];
		$sousuokey = $_GET['sousuokey'];
		if (empty($list_page)) $list_page = 1;
		if (empty($list_num)) $list_num = 10;
		if ($list_page < 5) {$list_page0 = 1;} else {$list_page0 = $list_page-4;}
		if ($list_page < 5) {$list_page1 = 1;} else {$list_page1 = $list_page-3;}
		if ($list_page < 5) {$list_page2 = 2;} else {$list_page2 = $list_page-2;}
		if ($list_page < 5) {$list_page3 = 3;} else {$list_page3 = $list_page-1;}
		if ($list_page < 5) {$list_page4 = 4;} else {$list_page4 = $list_page;}
		if ($list_page < 5) {$list_page5 = 5;} else {$list_page5 = $list_page+1;}
		if ($list_page < 5) {$list_page6 = 6;} else {$list_page6 = $list_page+2;}
		if ($list_page < 5) {$list_page7 = 7;} else {$list_page7 = $list_page+3;}
		if ($list_page < 5) {$list_page8 = 8;} else {$list_page8 = $list_page+4;}
		$page_btn .= "<button type='button' class='btn btn-white' onClick='list_page_go(".$list_page0.")'><i class='fa fa-chevron-left'></i></button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page1."' onClick='list_page_go(".$list_page1.")'>".$list_page1."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page2."' onClick='list_page_go(".$list_page2.")'>".$list_page2."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page3."' onClick='list_page_go(".$list_page3.")'>".$list_page3."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page4."' onClick='list_page_go(".$list_page4.")'>".$list_page4."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page5."' onClick='list_page_go(".$list_page5.")'>".$list_page5."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page6."' onClick='list_page_go(".$list_page6.")'>".$list_page6."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page7."' onClick='list_page_go(".$list_page7.")'>".$list_page7."</button>";
		$page_btn .= "<button type='button' class='btn btn-white' onClick='list_page_go(".$list_page8.")'><i class='fa fa-chevron-right'></i></button>";
		$list_limit = ($list_page-1)*$list_num.",".$list_num;
		if (empty($sousuokey)) {
			$sql = "SELECT * from `system` limit ".$list_limit;
		} else {
			$sql = "SELECT * from `system` WHERE `sub_name` = '".$sousuokey."'";
		}
		$result = mysql_query($sql,$mysql_conn);
		while(@$row=mysql_fetch_array($result)) {
			$sub_id = $row['sub_id'];
			$sub_type = $row['sub_type'];
			$sub_name = $row['sub_name'];
			$sub_access = $row['sub_access'];
			$sublist .= "<tr><td>";
			$sublist .= "    <input type='checkbox' class='i-checks' name='input[]'>";
			$sublist .= "</td>";
			$sublist .= "<td>".$sub_id."</td>";
			$sublist .= "<td>".$sub_type."</td>";
			$sublist .= "<td>".$sub_access."</td>";
			$sublist .= "<td>".$sub_name."</td>";
			$sublist .= "<td>";
			$sublist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_system_view(".$sub_id.");'><i class='fa fa-edit'></i> 配置 </a>";
			$sublist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_system_edit(".$sub_id.");'><i class='fa fa-edit'></i> 编辑 </a>";
			$sublist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_system_del(".$sub_id.");'><i class='fa fa-trash-o'></i> 删除 </a>";
			$sublist .= "</td></tr>";
		}
		require($v_file);
	}
	function admin_system_add() 
	{ 
		global $mysql_conn,$v_file;
		require($v_file);
	}
	function admin_system_add_do() 
	{ 
		global $mysql_conn;
		$sub_type = $_POST['sub_type'];
		$sub_name = $_POST['sub_name'];
		$sub_access = $_POST['sub_access'];
		$sql = "SELECT * from `system` WHERE `sub_access` = '".$sub_access."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		if (empty($row)) {
			$sql="INSERT INTO system (sub_id, sub_type, sub_name, sub_access) VALUES (NULL,'$sub_type','$sub_name','$sub_access')";
			$result = mysql_query($sql,$mysql_conn);
			@$row = mysql_fetch_array($result);
			echo "2";//模块添加成功
		} else {
			echo  "1";//标识名已存在
		}
	}
	function admin_system_view() 
	{ 
		global $mysql_conn,$v_file;
		$sub_id = $_GET['sub_id'];
		$sql = "SELECT * from `system` WHERE `sub_id` = '".$sub_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$sub_type = $row['sub_type'];
		if ($sub_type == "system") $sub_type_name = "系统模块";
		if ($sub_type == "plus") $sub_type_name = "功能模块";
		$sub_name = $row['sub_name'];
		$sub_access = $row['sub_access'];
		$sql_user_type = "SELECT * from `user_type` ";
		$result_user_type = mysql_query($sql_user_type,$mysql_conn);
		while(@$row_user_type=mysql_fetch_array($result_user_type)) {
			$type_id = $row_user_type['type_id'];
			$type_name = $row_user_type['type_name'];
			$typelist .= "<td><div class='btn-group'>";
			$typelist .= "<button class='btn btn-success btn-xs' type='button'>".$type_id."</button><button class='btn btn-info btn-xs' type='button'>".$type_name."</button>";
            $typelist .= "</div></td>";
		}
		$sql_conf = "SELECT * from `".$sub_access."_conf` WHERE `conf_c` = '1'";
		$result_conf = mysql_query($sql_conf,$mysql_conn);
		while(@$row_conf=mysql_fetch_array($result_conf)) {
			$conf_id = $row_conf['conf_id'];
			$conf_sub = $row_conf['conf_sub'];
			$conf_name = $row_conf['conf_name'];
			$conf_islogin = $row_conf['conf_islogin'];
			$conf_istype = $row_conf['conf_istype'];
			$conflist .= "<tr>";
			$conflist .= "<td>".$conf_id."</td>";
			$conflist .= "<td>".$conf_name."<input type='hidden' class='form-control' value='".$sub_access."' id='".$conf_id."_access'></td>";
			$conflist .= "<td><select class='form-control' name='".$conf_id."_islogin' id='".$conf_id."_islogin'>";
			if ($conf_islogin == "1") {
				$conflist .= "<option value='1' selected>是</option><option value='0'>否</option>";
			} else {
				$conflist .= "<option value='1'>是</option><option value='0' selected>否</option>";
			}		
			$conflist .= "</select></td>";
			$conflist .= "<td><input type='text' class='form-control' value='".$conf_istype."' id='".$conf_id."_istype'></td>";
			$conflist .= "<td><a href='#' class='btn btn-primary btn-xs' onclick='admin_system_view(".$conf_id.");' >提交</a></td>";
			$conflist .= "</tr>";
		}
		require($v_file);
	}
	function admin_system_view_do() 
	{ 
		global $mysql_conn;
		$conf_id = $_POST['conf_id'];
		$conf_islogin = $_POST['conf_islogin'];
		$conf_istype = $_POST['conf_istype'];
		$sub_access = $_POST['sub_access'];
		$sql = "UPDATE `".$sub_access."_conf` SET `conf_islogin` = '".$conf_islogin."', `conf_istype` = '".$conf_istype."' WHERE `conf_id` ='".$conf_id."';";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "1";//编辑成功
	}
	function admin_system_edit() 
	{ 
		global $mysql_conn,$v_file;
		$sub_id = $_GET['sub_id'];
		$sql = "SELECT * from `system` WHERE `sub_id` = '".$sub_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$sub_type = $row['sub_type'];
		$sub_name = $row['sub_name'];
		$sub_access = $row['sub_access'];
		require($v_file);
	}
	function admin_system_edit_do() 
	{ 
		global $mysql_conn;
		$sub_id = $_POST['sub_id'];
		$sub_type = $_POST['sub_type'];
		$sub_name = $_POST['sub_name'];
		$sub_access = $_POST['sub_access'];
		$sql = "SELECT * from `system` WHERE `sub_access` = '".$sub_access."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		if (empty($row)) {
			$sql = "UPDATE `system` SET `sub_type` = '".$sub_type."', `sub_name` = '".$sub_name."', `sub_access` = '".$sub_access."' WHERE `sub_id` ='".$sub_id."';";
			$result = mysql_query($sql,$mysql_conn);
			@$row = mysql_fetch_array($result);
			echo "2";//编辑成功
		} else {
			echo "1";//如果有重名的标识符，提示修改失败
		}
	}
	function admin_system_del_do() 
	{ 
		global $mysql_conn;
		$sub_id = $_POST['sub_id'];
		$sql = "DELETE from `system` WHERE `sub_id` = '".$sub_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "2";
	}
} 
/* End of file democontroller.php */ 